﻿Imports System.Speech
Imports System.Speech.Synthesis
Imports System.Speech.Recognition
Imports System.Windows
Imports System.Threading

Public Class VoiceTest
    Inherits System.Web.UI.Page

    'Creating variables
    Dim ss As New Speech.Synthesis.SpeechSynthesizer

    Dim pb As New PromptBuilder

    Dim clist As New Choices
    Private WithEvents sre As New System.Speech.Recognition.SpeechRecognitionEngine(System.Globalization.CultureInfo.GetCultureInfo("en-US"))


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub


    Private Sub sre_SpeechRecognized(sender As Object, e As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles sre.SpeechRecognized
        Select Case (e.Result.Text.ToString)
            Case "Hello"
                ss.SpeakAsync("Hello George")
        End Select

        tb_text.Text = e.Result.Text.ToString

    End Sub


    Protected Sub btn_start_Click(sender As Object, e As EventArgs) Handles btn_start.Click
        btn_start.Enabled = False
        btn_stop.Enabled = True
        clist.Add("Hello")
        clist.Add("hi")
        Dim gr As New Grammar(New GrammarBuilder(clist))


        sre.RequestRecognizerUpdate()
        sre.LoadGrammar(New System.Speech.Recognition.DictationGrammar)
        sre.SetInputToDefaultAudioDevice()
        AddHandler sre.SpeechRecognized, AddressOf sre_SpeechRecognized
        sre.RecognizeAsync(Speech.Recognition.RecognizeMode.Multiple)
        tb_text.Text = ""
    End Sub

    
    Protected Sub btn_stop_Click(sender As Object, e As EventArgs) Handles btn_stop.Click
        tb_text.Text = "end"
    End Sub
End Class